package com.zqq.base.permission;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;

import com.zqq.base.ActivityManager;
import com.zqq.base.dialog.PermissionDialog;
import com.zqq.base.utils.LogUtils;

import pub.devrel.easypermissions.helper.BaseSupportPermissionsHelper;


public class PermissionsHelperProxy<T> extends BaseSupportPermissionsHelper {

    @SuppressLint("RestrictedApi")
    private BaseSupportPermissionsHelper<T> permissionsHelper;
    private PermissionDialog permissionDialog;

    @SuppressLint("RestrictedApi")
    public PermissionsHelperProxy(BaseSupportPermissionsHelper<T> permissionHelper) {
        super(permissionHelper.getHost());
        this.permissionsHelper = permissionHelper;
    }

    @SuppressLint("RestrictedApi")
    @Override
    public FragmentManager getSupportFragmentManager() {
        return permissionsHelper.getSupportFragmentManager();
    }

    @SuppressLint("RestrictedApi")
    @Override
    public void directRequestPermissions(int requestCode, @NonNull String... perms) {
        permissionsHelper.directRequestPermissions(requestCode, perms);
    }

    @SuppressLint("RestrictedApi")
    @Override
    public boolean shouldShowRequestPermissionRationale(@NonNull String perm) {
        return permissionsHelper.shouldShowRequestPermissionRationale(perm);
    }

    @SuppressLint("RestrictedApi")
    @Override
    public Context getContext() {
        return permissionsHelper.getContext();
    }

    @SuppressLint("RestrictedApi")
    @Override
    public void showRequestPermissionRationale(@NonNull String rationale, @NonNull String positiveButton, @NonNull String negativeButton, int theme, int requestCode, @NonNull String... perms) {
        LogUtils.i("bl_permission", "rationale>>" + rationale);
        PermissionDialog.getInstance().createDialog(getContext())
                .setUnCancle()
                .setMsg(rationale)
                .setLeft(negativeButton)
                .setRight(positiveButton)
                .setOnLinsener(new PermissionDialog.OnLinsener() {
                    @Override
                    public void onShow(DialogInterface dialog) {

                    }

                    @Override
                    public void onDismiss(DialogInterface dialog) {

                    }

                    @Override
                    public void onClick(AlertDialog dialog, int type) {
                        if(type == 1){
                            PermissionPageManagement.ApplicationInfo(ActivityManager.getInstance().currentActivity());
                        }
                    }
                });
    }
}
